/*
 * Copyright (c) 2009, artur
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the author nor the names of any co-contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

/*
 * kiddie -os
 * 08.05.2009
 * include/sys/mem.h - Memory data types
 *
 */

#ifndef MEM_H_
#define MEM_H_

#include <sys/types.h>

#define MAX_ORDER 10

#define PAGE_MASK       (PAGE_SIZE-1)
#define PAGE_ALIGN(n)   ((((vaddr_t)(n)) + PAGE_MASK) & (vaddr_t)~PAGE_MASK)
#define PAGE_TRUNC(n)   (((vaddr_t)(n)) & (vaddr_t)~PAGE_MASK)


/**
 * free pages block
 */
struct p_block {
	struct p_block *prev;	/* previous free page block, virtual address */
	struct p_block *next;	/* next free page block, virtual address */
	size_t size;	/* size of block in bytes */
};

/**
 * page/memory block structure
 */
#define MEM_OPEN_TAG	0x11223344
#define MEM_CLOSE_TAG	0x44332211
struct m_block {
	uint32_t	m_open_tag;	/* */
	vaddr_t		m_addr;
	size_t		m_length;	/* size of block */
	uint32_t	m_flags;	/* status of memory block */
	struct m_block *prev;	/* previous memory block, virtual address */
	struct m_block *next;	/* next memory block, virtual address */
	uint32_t	m_close_tag;	/* */
};


typedef struct p_block p_block_t;
typedef struct m_block m_block_t;

#endif /*MEM_H_*/
